<template>
  <div class="console-zone__nav">
    <div class="module-list" @click="activeMenuIndex = -1">
      <div v-for="(v,i) in menus" :key="v.key" class="module-list-item" :class="{'module-list-item__checked':i===activeMenuIndex}" @click.stop="menuClickHandle(v,i)">
        <a class="module__name">{{ v.name }}</a>
        <div v-show="activeMenuIndex === i" class="module_pop" style="left:94px;top:28px">
          <ul class="module-parts">
            <li v-for="(m) in v.subMenus" :key="m.key" class="module-parts-item" draggable="true" @dragstart="e => dragstartHandler(e, m)">
              <div class="module-parts-thumb">
                <img>
              </div>
              <span>{{ m.name }}</span>
            </li>
          </ul>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import BasicElements from '@/assets/BasicElements'
export default {
  name: 'MainLeft',
  data() {
    return {
      activeMenuIndex: -1,
      menus: BasicElements
    }
  },
  computed: {},
  created() {
    document.addEventListener('click', this.outClick)
  },
  beforeDestroy() {
    document.removeEventListener('click', this.outClick)
  },
  mounted() {},
  methods: {
    outClick(e) {
      if (!this.$el.contains(e.target)) {
        this.activeMenuIndex = -1
      }
    },
    menuClickHandle(v, i) {
      this.activeMenuIndex = i
    },
    dragstartHandler(e, item) {
      e.dataTransfer.dropEffect = 'copy'
      e.dataTransfer.effectAllowed = 'all'
      e.dataTransfer.setData('text/plain', JSON.stringify(this.initItem(item)))
    },
    initItem(item) {
      return { zIndex: 'auto', top: 0, left: 0, bottom: 'auto', right: 'auto', ...item }
    }
  }
}
</script>
<style scoped>
.console-zone__nav {
  position: absolute;
  width: 84px;
  top: 0;
  left: 0;
  bottom: 0;
}
.module-list {
  width: 100%;
  height: 100%;
  background: #202020;
  position: relative;
}
.module-list .module-list-item {
  height: 84px;
  background: #202020;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
  cursor: pointer;
}
.module-list .module-list-item:hover {
    background: #404040;
}
.module-list .module-list-item:hover>.module-ico, .module-list .module-list-item:hover>.module__name {
    color: #23c312;
}
.module-list .module-list-item .module_pop {
  position: absolute;
  height: 348px;
  left: 80px;
  padding-top: 6px;
  padding-bottom: 6px;
  background: #202020;
  z-index: 999999;
  overflow-y: auto;
  overflow-x: hidden;
  border-radius: 2px;
  box-shadow: 0 5px 14px 0 rgba(0, 0, 0, 0.2);
}
.module-list .module-list-item__checked {
  background: #404040;
}
.module-list .module-list-item > .module__name {
  font-size: 12px;
  color: #999;
}
.module-list > .module-list-item__checked > .module__name {
  color: #23c312;
}
.module-list ul.module-parts li.module-parts-item:nth-child(3n) {
  margin-left: 12px;
  margin-right: 24px;
}
.module-list ul.module-parts li.module-parts-item:nth-child(3n + 1) {
  margin-left: 24px;
}
.module-list ul.module-parts li.module-parts-item:nth-child(3n + 2) {
  margin-left: 12px;
}
.module-list ul.module-parts {
  margin: 0;
  padding: 12px 0 0;
  width: 336px;
  overflow: auto;
  list-style: none;
}
.module-list ul.module-parts li.module-parts-item {
  font-size: 12px;
  float: left;
  margin-top: 0;
  margin-bottom: 35px;
  text-align: center;
  cursor: pointer;
  width: 88px;
  height: 56px;
}
.module-list ul.module-parts .module-parts-thumb {
  margin: auto;
  width: 100%;
  height: 100%;
  background: #2e2e2e;
}
.module-list ul.module-parts .module-parts-thumb > img {
  width: 100%;
  height: 100%;
}
.module-list ul.module-parts li.module-parts-item > span {
  margin-top: 3px;
  font-size: 12px;
  display: inline-block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 94px;
  color: #999;
}
</style>

